﻿using System;
using System.Diagnostics;
using Internal.UIOC;
using UIOC;
using UIOC.Attributes;

namespace UIOC {

    public interface IObject {

        bool IsDisposed { get; }
    }

#if !DISABLE_DEBUGGER_ATTRIBUTE
    [DebuggerStepThrough]
    [DebuggerNonUserCode]
#endif
    [SkipInternalValidation]
    public abstract class Object : IObject, IObjectInternal, IPooledObjectInternal, IBeanObjectInternal, IAutowiredInternal {

        bool IObject.IsDisposed => throw new NotImplementedException();

        [Internal]
        [Obsolete]
#if !DISABLE_DEBUGGER_ATTRIBUTE
        [DebuggerHidden]
#endif
        protected virtual void Internal__Autowired_Construct__() { }
#pragma warning disable CS0612 // 类型或成员已过时
#if !DISABLE_DEBUGGER_ATTRIBUTE
        [DebuggerHidden]
#endif
        void IAutowiredInternal.Construct() => Internal__Autowired_Construct__();
#pragma warning restore CS0612 // 类型或成员已过时
        protected virtual void Construct() { }
#if !DISABLE_DEBUGGER_ATTRIBUTE
        [DebuggerHidden]
#endif
        void IObjectInternal.Construct() {
            if (this is IAutowiredInternal autowired) {
                autowired.Construct();
            }
            Construct();
        }

        [Internal]
        [Obsolete]
#if !DISABLE_DEBUGGER_ATTRIBUTE
        [DebuggerHidden]
#endif
        protected virtual void Internal__Autowired_Allocate__() { }
#pragma warning disable CS0612 // 类型或成员已过时
#if !DISABLE_DEBUGGER_ATTRIBUTE
        [DebuggerHidden]
#endif
        void IAutowiredInternal.Allocate() => Internal__Autowired_Allocate__();
#pragma warning restore CS0612 // 类型或成员已过时
        protected virtual void Allocate() { }
#if !DISABLE_DEBUGGER_ATTRIBUTE
        [DebuggerHidden]
#endif
        void IPooledObjectInternal.Allocate() {
            if (this is IAutowiredInternal autowired) {
                autowired.Allocate();
            }
            Allocate();
        }

        [Internal]
        [Obsolete]
#if !DISABLE_DEBUGGER_ATTRIBUTE
        [DebuggerHidden]
#endif
        protected virtual void Internal__Autowired_Release__() { }
#pragma warning disable CS0612 // 类型或成员已过时
#if !DISABLE_DEBUGGER_ATTRIBUTE
        [DebuggerHidden]
#endif
        void IAutowiredInternal.Release() => Internal__Autowired_Release__();
#pragma warning restore CS0612 // 类型或成员已过时
        protected virtual void Release() { }
#if !DISABLE_DEBUGGER_ATTRIBUTE
        [DebuggerHidden]
#endif
        void IPooledObjectInternal.Release() {
            Release();
            if (this is IAutowiredInternal autowired) {
                autowired.Release();
            }
        }

        [Internal]
        [Obsolete]
#if !DISABLE_DEBUGGER_ATTRIBUTE
        [DebuggerHidden]
#endif
        protected virtual void Internal__Autowired_Dispose__() { }
#pragma warning disable CS0612 // 类型或成员已过时
#if !DISABLE_DEBUGGER_ATTRIBUTE
        [DebuggerHidden]
#endif
        void IAutowiredInternal.Dispose() => Internal__Autowired_Dispose__();
#pragma warning restore CS0612 // 类型或成员已过时
        protected virtual void Dispose() { }
#if !DISABLE_DEBUGGER_ATTRIBUTE
        [DebuggerHidden]
#endif
        void IObjectInternal.Dispose() {
            Dispose();
            if (this is IAutowiredInternal autowired) {
                autowired.Dispose();
            }
        }
    }
}

namespace Internal.UIOC {

    public interface IBeanObjectInternal : IObject {
    }

    public interface IPooledObjectInternal : IObject {

        void Allocate();

        void Release();
    }

    public interface IObjectInternal : IObject {

        void Construct();

        void Dispose();
    }
}